<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="gray-bg">

	<div class="ui-layout-west">
		<div class="main-content">
			<div class="box box-main" style="width: 3000px">
				<div class="box-header">
					<div class="box-title">
						<i class="fa icon-grid"></i> 终端列表
					</div>
					<div class="box-tools pull-right">
						<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;">
							<i class="fa fa-chevron-up"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠">
							<i class="fa fa-chevron-down"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新">
							<i class="fa fa-refresh"></i></button>
					</div>
				</div>
				<div class="ui-layout-content">
					<div id="tree" class="ztree" style="overflow: auto"></div>
				</div>
			</div>
		</div>
	</div>


	<div class="container-div ui-layout-center">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li hidden>
								所属分组：<input type="text" name="aid" id="aid" />
							</li>
							<li>
								终端编号：<input type="text" name="tid" id="tid"/>
							</li>

							<li>
								所属分组：<input type="text" name="aname"/>
							</li>

							<li>
								终端名称：<input type="text" name="tname"/>
							</li>

							<li>
								流量使用范围：<input type="text" name="minNum" placeholder="最小值" style="width:100px" />MB ~ <input type="text" name="maxNum" placeholder="最大值"  style="width:100px" />MB
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="broad:traffic:add">-->
					<!--<i class="fa fa-plus"></i> 添加-->
				<!--</a>-->
				<!--<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="broad:traffic:edit">
					<i class="fa fa-edit"></i> 设置终端流量限制
				</a>-->
				<!--<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="broad:traffic:remove">
					<i class="fa fa-remove"></i> 批量设置流量限制
				</a>-->
                <input type="text" name="rdsNum" id="aidgroup" width="50px" onclick="selectAidTree()" placeholder="选择区域终端" autocomplete="off"/>
				<input type="text" name="rdsNum" id="rdsNum" width="50px" autocomplete="off"/>
				<a class="btn btn-del btn-del" onclick="rdsAreaSet()">
					区域设置限制流量/MB
				</a>
                <a class="btn btn-info btn-del disabled" onclick="rdsSet()">
                     批量勾选设置限制流量/MB
                </a>
				<!--<input type="text" name="fmfrequencyNum" id="fmfrequencyNum" width="50px"/>-->
				<!--<a class="btn btn-warning btn-del disabled" onclick="fmfrequency()">-->
					<!--批量设置限终端启用-->
				<!--</a>-->
				<!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="broad:traffic:export">-->
						<!--<i class="fa fa-download"></i> 导出-->
				 <!--</a>-->
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
	<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('broad:traffic:edit')}]];
        var removeFlag = [[${@permission.hasPermi('broad:traffic:remove')}]];
		var datas = [[${@dict.getType('sys_traffic_status')}]];
		var data2s = [[${@dict.getType('sys_tem_staus')}]];
        var prefix = ctx + "broad/traffic";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                rdsSetUrl: prefix + "/rdsSet",
				fmfrequencyUrl: prefix + "/fmfrequencySet",
                modalName: "流量",
				search: false,
		        showExport: true,
                columns: [
                    {
		            checkbox: true
		        },
				{
					field : 'tid',
					title : '终端流量使用信息表编号',
					visible: false
				},
				{
					field : 'tid', 
					title : '终端编号',
					sortable: true
				},
					{
						field : 'tname',
						title : '终端名称',
						sortable: true
					},
					{
						field : 'aname',
						title : '所属分组',
						sortable: true
					},
					{
						field : 'uname',
						title : '上级分组',
						sortable: true
					},
				{
					field : 'usetraffic', 
					title : '使用流量/MB',
					sortable: true,
					formatter: function(value, row, index) {
						if(row.sdf!=null){
							var sd = row.sd.substr(0,row.sd.indexOf("M"));
							var sdf = row.sdf.substr(0,row.sdf.indexOf("M"));
							return Number(sd)-Number(sdf);
						}else{
							return "-"
						}
					}
				},
				{
					field : 'trafficlimit',
					title : '流量限制/MB',
					sortable: true
				},
				{
					field: 'trafficlimit',
					title: '状态',
					align: 'center',
					formatter: function(value, row, index) {
                        if (value > 0)
                            return '<a class="btn btn-xs btn-primary" >正常</a>';
                        else
                            return '<a class="btn btn-xs btn-danger" >超量</a>';
					}
				},
				{
					field : 'lasttime', 
					title : '流量统计时间',
					sortable: true
				},
				{
					field: 'trafficlimit',
					title: '启用状态',
					sortable: true,
					formatter: function (value, row, index) {
						if (value > 0)
							return '<a class="btn btn-xs btn-primary" >启用</a>';
						else
							return '<a class="btn btn-xs btn-danger" >停用</a>';
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	// actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.ttid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.ttid + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }
		        ]
            };
            $.table.init(options);
        });

        function rdsSet() {
            var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要更加选中的" + rows.length + "条数据的限制流量吗?", function() {
                var url = $.table._option.rdsSetUrl;
                var rdsNumber = document.getElementById("rdsNum").value;
                var data = {"ids": rows.join(),"number": rdsNumber};
                $.operate.submit(url, "post", "json", data);
            });
        }

		function rdsAreaSet() {
			var rows = $("#aidgroup").val().slice(1).split(",")
			$.modal.confirm("确认要更加选中的" + rows.length + "条数据的限制流量吗?", function() {
				var url = $.table._option.rdsSetUrl;
				var rdsNumber = document.getElementById("rdsNum").value;
				var data = {"ids": rows.join(),"number": rdsNumber};
				$.operate.submit(url, "post", "json", data);
			});
		}

		function fmfrequency() {
			var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要更加选中的" + rows.length + "条数据的终端启用吗?", function() {
				var url = $.table._option.fmfrequencyUrl;
				var fmfrequencyNumber = document.getElementById("#fmfrequencyNum").value;
				var data = {"ids": rows.join(),"number": fmfrequencyNumber};
				$.operate.submit(url, "post", "json", data);
			});
		}
        String.prototype.trim=function(){
            return this.replace(/(^\s*)|(\s*$)/g, "");
        }
        $("#tid").change(function(){
            $(this).val($(this).val().trim());
        });

		/*用户管理-新增-选择用户所属区域树*/
		function selectAidTree() {
			var options = {
				title: '选择区域',
				width: "380",
				url: "/broad/traffic/selectAidTree",
					callBack: doSubmitAid
			};
			$.modal.openOptions(options);
		}

		//选择树的回调方法
		function doSubmitAid(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			var nodes = tree.getCheckedNodes(true);
			nodes.forEach(function(item,index){
				if(item.aid.length==13){
					$("#aidgroup").val($("#aidgroup").val()+","+item.aid)
				}
			})
			layer.close(index);
		}

		$(function() {
			$('body').layout({ west__size: 185 });
			queryAreaList();
			queryAreaTree();
		});

		function queryAreaList() {

			var options = {
				url: prefix + "/list",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				exportUrl: prefix + "/export",
				removeUrl: prefix + "/remove",
				rdsSetUrl: prefix + "/rdsSet",
				fmfrequencyUrl: prefix + "/fmfrequencySet",
				exportBySingleUrl: prefix + "/exportbysingle",
				uniqueId: "tid",
				striped:true,
				modalName: "终端管理",
				showExport: true,
				search: false,
				// height: 800,
				columns: [{
					checkbox: true

				},
					{
						title : '操作',
						visible: true,
						width: 50 ,
						formatter: function (value, row, index) {
							var actions = [];
							actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="phoneEdit(\'' + row.tid + '\')"><i class="fa fa-edit" ></i>修改授权号码</a> ');
							actions.push('<a class="btn btn-success btn-xs '+editFlag + '" href="#" onclick="$.operate.edit(\'' + row.tid + '\')"><i class="fa fa-edit" ></i>编辑</a> ');
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.tid + '\')"><i class="fa fa-remove"></i>删除</a>');
							return  $.table.dropdownToggle(actions.join(''));
						}
					},
					{
						field : 'tid',
						title : '终端IMEI',
						visible: true,
						align: 'center'
					},
					{
						field : 'tname',
						title : '终端名称(编号)',
						align: 'center'
					},
					{
						field : 'uname',
						title : '所属用户',
						align: 'center'
					},
					{
						field : 'aname',
						title : '所属分组',
						align: 'center'
					},
					{
						field : 'lastaccesstime',
						title : '最后访问日期',
						align: 'center'
					},
					{
						field : 'intertime',
						title : '交互时间',
						align: 'center'
					},
					{
						field : 'terminaltype',
						title : '终端类型',
						align: 'center',
						formatter: function(value, row, index) {
							if(value==1){
								return "应急广播终端";
							}else if(value==2){
								return "后备能源型终端";
							}else if(value==2){
								return "发射机型终端";
							}
						}
					},
					{
						field : 'longitude',
						title : '终端经度',
						align: 'center'
					},
					{
						field : 'latitude',
						title : '终端纬度',
						align: 'center'
					},
					{
						field : 'basestation',
						title : '基站编码',
						align: 'center'
					},
					{
						field : 'poscene',
						title : '现场照片',
						visible: true,
						align: 'center',
						formatter: function(value, row, index) {
							if(value){
								return $.table.imageView(ctx+value,50,50);
							}else {
								return value;
							}
						}
					},
					{
						field : 'phone',
						title : '终端手机号码',
						align: 'center'
					},
					{
						field : 'ypowerconsumption',
						title : '年耗电量',
						align: 'center'
					},
					{
						field : 'brfrequency',
						title : '流量使用情况（月）',
						visible: true,
						align: 'center'
					},
					{
						field : 'maintenanceFunds',
						title : '年维护经费',
						align: 'center'
					},
					{
						field : 'irfrequency',
						title : '对讲接收频率',
						visible: true,
						align: 'center'
					},
					{
						field : 'onlinestate',
						title : '在线状态',
						align: 'center'
					},
					{
						field : 'dcs',
						title : 'DCS码',
						align: 'center'
					},
					{
						field : 'address',
						title : '终 端 的 地 址',
						align: 'center'
					},
					{
						field : 'atphone',
						title : '终端授权号码',
						visible: true,
						align: 'center'
					},
					{
						field : 'facid',
						title : '出厂编号',
						visible: true,
						align: 'center'
					},
					{
						field : 'nettype',
						title : '网络类型',
						visible: true,
						align: 'center'
					},
					{
						field : 'eovolume',
						title : '终端音量',
						visible: true,
						align: 'center'
					},
					{
						field : 'rds',
						title : 'RDS码',
						visible: true,
						align: 'center'
					},
					{
						field : 'transmitfrequency',
						title : '发射频率',
						align: 'center'
					},
					{
						field : 'transmitpower',
						title : '发射功率',
						align: 'center'
					},
					{
						field : 'reflectedpower',
						title : '反射功率',
						align: 'center'
					},
					{
						field : 'workvoltage',
						title : '工作电压',
						align: 'center'
					},
					{
						field : 'batteryvoltage',
						title : '电池电压',
						align: 'center'
					},
					{
						field : 'loadcurrent',
						title : '负载电流',
						align: 'center'
					},
					{
						field : 'pdmode',
						title : '供电模式',
						visible: true,
						align: 'center'
					},
					{
						field : 'chargecurrent',
						title : '充电电流',
						visible: true,
						align: 'center'
					},
					{
						field : 'brfrequency',
						title : '广播接收频率',
						visible: true,
						align: 'center'
					},
					{
						field : 'manager',
						title : '终端管理员',
						align: 'center'
					},
					{
						field : 'managertel',
						title : '管理员电话',
						align: 'center'
					},
					{
						field : 'createdtime',
						title : '创 建 的 时 间',
						align: 'center'
					},
					{
						field: 'isuse',
						title: '是否启用',
						align: 'center',
						formatter: function (value, row, index) {
							if(value == 1)
								return "是";
							else
								return "否";
						}
					},
					{
						field : 'aid',
						title : '终端地域id',
						visible: true,
						align: 'center',
						sortable: false
					},
					{
						field : 'parentaid',
						title : '终端父地域id',
						visible: false,
						align: 'center'
					},
					{
						field : 'hbtime',
						title : '心跳包时间',
						align: 'center'
					}
				]
			};
			$.table.init(options);
		};

		function queryAreaTree(){
			var url = ctx + "broad/area/treeData";
			var options = {
				url: url,
				onClick : zOnClick
			};
			$.tree.init(options);

			function zOnClick(event, treeId, treeNode) {
				aid1 = treeNode.id;
				$("#aid").val(treeNode.id);
				$.table.search();
			}
			$.tree.init(options);
		}

	</script>
</body>
</html>